﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<!-- 3. Write a function that finds all the occurrences of word in a text  -->
	<title></title>
	<link href="js-console.css" rel="stylesheet" />
	<style>
		textarea, button, input {
			width: 800px;
			display: block;
		}

		strong {
			color: green;
		}
	</style>
</head>
<body>
	<input type="text" id="txtWord" placeholder="Enter word here" />
	<textarea id="taText" placeholder="Enter input text here"></textarea>
	<button onclick="findAll()">Find all the occurrences of word in a text</button>
	<div id="js-console"></div>
	<script src="js-console.js"></script>
	<script>
		function findAll() {
			var word = jsConsole.read("#txtWord").toUpperCase();
			var text = jsConsole.read("#taText");

			var words = text.split(' ');
			var output = "";
			for (var i = 0; i < words.length; i++) {
				if (words[i].toUpperCase() == word) {
					output += "<strong>" + words[i] + "</strong> ";
				}
				else if (words[i].substring(0, words[i].length - 1).toUpperCase() == word) {
					output += "<strong>" + words[i].substring(0, words[i].length - 1) + "</strong>" +
						words[i].substring(words[i].length - 1) + " ";
				}
				else {
					output += words[i] + ' ';
				}
			}

			jsConsole.writeLine(output);
		}
	</script>
</body>
</html>
